from gis.common.django_ext.forms import BaseSchema, PaginationSchema, EnumField
from marshmallow import fields

from itpay.core.agency.const import PayType, ReceiptType
from itpay.core.recharge_order.const import (
    OrderStatus,
    RechargeSourceType,
    OrderCommentStar,
    OrderCommentRank,
)


class ListOrdersSchema(PaginationSchema):
    order_id = fields.Integer()
    agency_id = fields.Integer()
    agency_name = fields.String()
    mch_id = fields.Integer()
    user_id = fields.String()
    mch_recharge_id = fields.String()
    receipt_address_id = fields.Integer()
    status = EnumField(OrderStatus)
    amount_gte = fields.Integer()
    amount_lte = fields.Integer()
    pay_type = EnumField(PayType)
    source = EnumField(RechargeSourceType)
    created_at_begin = fields.DateTime()
    created_at_end = fields.DateTime()
    updated_at_begin = fields.DateTime()
    updated_at_end = fields.DateTime()
    success_at_begin = fields.DateTime()
    success_at_end = fields.DateTime()


class AddOrderSchema(BaseSchema):
    mch_id = fields.Integer(required=True)
    user_id = fields.String(required=True)
    recharge_amount = fields.Integer(required=True)
    amount = fields.Integer()
    real_amount = fields.Integer()
    pay_type = EnumField(PayType)
    receipt_address_id = fields.Integer()
    remark = fields.String(allow_none=True)


class ChangeOrderStatusSchema(BaseSchema):
    remark = fields.String(required=True)


class OrderCommentSchema(PaginationSchema):
    order_id = fields.Integer()
    agency_id = fields.Integer()
    agency_name = fields.String()
    mch_id = fields.Integer()
    user_id = fields.String()
    comment_star = EnumField(OrderCommentStar)
    comment_rank = EnumField(OrderCommentRank)
    receipt_type = EnumField(ReceiptType)
    pay_type = EnumField(PayType)
    created_at_begin = fields.DateTime()
    created_at_end = fields.DateTime()
    updated_at_begin = fields.DateTime()
    updated_at_end = fields.DateTime()
    auto_comment = fields.Boolean()
